package cn.disicn.common;

import java.io.Serializable;

public class ServerResponse<T> implements Serializable {

	private static final long serialVersionUID = 1L;
	
	private int status;
	private String msg;
	private T data;

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public ServerResponse(int status) {
		this.status = status;
	}

	public ServerResponse(int status, T data) {
		this.status = status;
		this.data = data;
	}

	public ServerResponse(int status, String msg) {
		this.status = status;
		this.msg = msg;
	}

	public ServerResponse(int status, String msg, T data) {
		super();
		this.status = status;
		this.msg = msg;
		this.data = data;
	}

	public boolean isSuccess() {
		return this.status == 0;
	}

	public static <T> ServerResponse<T> createBySuccess() {
		return new ServerResponse<T>(0);
	}

	public static <T> ServerResponse<T> createBySuccess(T data) {
		return new ServerResponse<T>(0, data);
	}

	public static <T> ServerResponse<T> createBySuccessMsg(String msg) {
		return new ServerResponse<T>(0, msg);
	}

	public static <T> ServerResponse<T> createBySuccessMsg(String msg, T data) {
		return new ServerResponse<T>(0, msg, data);
	}

	public static <T> ServerResponse<T> createByError() {
		return new ServerResponse<T>(1);
	}

	public static <T> ServerResponse<T> createByErrorMsg(String msg) {
		return new ServerResponse<T>(1, msg);
	}

}
